﻿@model Citi.ReportManager.WebUi.Models.ReportModel
<div id="divFiles">
    <h2>
        @if (Model.CurrentFolder == null || string.IsNullOrWhiteSpace(Model.CurrentFolder.Path))
        {
            @Model.CurrentCategory.Name;
        }
        else
        {
            @Model.CurrentFolder.Name;
        }</h2>
    <br />
    <div id="divBreadCrumb">
        @for (int i = Model.BreadCrumbs.Count - 1; i >= 0; i--)
        {
            var item = Model.BreadCrumbs[i];

            if (item.Name == Model.CurrentCategory.Name && (Model.CurrentFolder == null || string.IsNullOrWhiteSpace(Model.CurrentFolder.Path)))
            {
            <text> @item.Name </text>
            }
            else
            {
                if (string.IsNullOrWhiteSpace(item.PathDownload))
                {
            @Ajax.ActionLink(item.Name, "ByCategory", new { categoryId = item.CategoryId }, new AjaxOptions { UpdateTargetId = "divFiles" }) 
                }
                else
                {
            @Ajax.ActionLink(item.Name, "ByCategory", "Report", new { categoryId = item.CategoryId, folder = item.PathDownload ?? null }, new AjaxOptions { UpdateTargetId = "divFiles" }, null)
                }
            }
            
            if (i > 0)
            {
            <text>&nbsp;>&nbsp;</text>
            }
        }
    </div>
    <br />
    @if (!Model.Items.Any())
    {
        <p>
            There's no report in this folder</p>
    }
    else
    {
        <table class="table table-bordered table-striped">
            <tr>
                <th>
                    Name
                </th>
                <th style="width: 60px">
                    Size
                </th>
            </tr>
            @foreach (var item in Model.Items)
            {
                <tr>
                    <td>
                        <img src="@Url.Content(string.Format("~/Content/Images/Files/{0}", item.Icon))" alt="File type" style="width: 24px"/>
                        &nbsp;
                        @if (item.Folder)
                        {
                            @*@Ajax.ActionLink(item.Name, "ByCategory", "Report", new { categoryId = item.CategoryId, folder = item.PathDownload ?? null }, new AjaxOptions { UpdateTargetId = "divFiles" }, null)*@
                            @Html.ActionLink(item.Name, "ByCategory", new { categoryId = item.CategoryId, folder = item.PathDownload ?? null })
                        }
                        else
                        {
                            @Html.ActionLink(item.Name, "Download", new { categoryId = item.CategoryId, folder = item.PathDownload ?? null })
                        }
                    </td>
                    @if (!item.Folder)
                    {
                        <td>@item.Size.ToString("#0.0") MB
                        </td>
                    }
                    else
                    {
                        <td>
                        </td>
                    }
                </tr>
            }
        </table>
    }
    <div>
        @if (Model.CurrentFolder != null && !string.IsNullOrWhiteSpace(Model.CurrentFolder.Name))
        {
            @Ajax.ActionLink("Voltar", "ByCategory", "Report", new { categoryId = Model.CurrentCategory.Id, folder = Model.CurrentFolder.PreviousFolder ?? null }, new AjaxOptions { UpdateTargetId = "divFiles" }, null)
        }
        else
        {
            @Ajax.ActionLink("Voltar", "ByCategory", new { categoryId = Model.CurrentCategory.ParentId }, new AjaxOptions { UpdateTargetId = "divFiles" })
        }
    </div>
</div>
